home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / util_math.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-03-22  |  2.9 KB  |  93 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #ifndef _UTIL_MATH_H
  8. #define _UTIL_MATH_H
  9.  
  10. #if defined(_MSC_VER)
  11. #define _USE_MATH_DEFINES
  12. #endif
  13. #include <cmath>
  14. #include <vector>
  15.  
  16. #include <QString>
  17. #include <QPolygon>
  18. #include <QList>
  19. #include <QPainterPath>
  20.  
  21. #include "scribusapi.h"
  22.  
  23. class FPoint;
  24. class FPointArray;
  25.  
  26.  
  27. /*! \brief Compare double values by pre-multiplying by 10000 and converting to long if possible.
  28. If premultiplication does not allow to store result in a long value, perform a standard comparison.
  29. */
  30. bool SCRIBUS_API compareDouble(double a, double b);
  31. FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
  32. FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
  33. inline double SCRIBUS_API xy2Deg(double x, double y);
  34. FPoint SCRIBUS_API projectPointOnLine(FPoint p, QPointF lineStart, QPointF lineEnd);
  35. QPolygon SCRIBUS_API FlattenPath(const FPointArray& ina, QList<uint> &Segs);
  36. QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
  37. QPainterPath SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota, double factor2 = 0.0);
  38. uint SCRIBUS_API getDouble(QString in, bool raw);
  39. inline double SCRIBUS_API sind(double);
  40. inline double SCRIBUS_API cosd(double);
  41. inline double SCRIBUS_API square(double);
  42. inline double SCRIBUS_API distance(double, double);
  43. /*! \brief Constrains an angle of rotation to 45 degree intervals
  44.    Will make code simpler and reduce interval or provide as a parameter
  45.    \param angle angle Angle in degrees
  46.    \param constrain contrain value in degrees
  47.    \retval double Constrained angle
  48.  */
  49. double SCRIBUS_API constrainAngle(double angle, double constrain);
  50. /*! \brief Get the rotation angle (in radian) from a transformation matrix
  51.    Will make code simpler and reduce interval or provide as a parameter
  52.    \param matrix the transformation matrix
  53.    \param def the value that should be return if matrix is not a rotation matrix
  54.    \retval double the rotation angle
  55.  */
  56. double SCRIBUS_API getRotationFromMatrix(QMatrix& matrix, double def);
  57.  
  58.  
  59. // IMPLEMENTATION
  60.  
  61. inline double square(double x)
  62. {
  63.     return x*x;
  64. }
  65.  
  66. inline double distance(double x, double y)
  67. {
  68.     return sqrt(x*x + y*y);
  69. }
  70.  
  71. inline double xy2Deg(double x, double y)
  72. {
  73.     return atan2(y,x) * (180.0/M_PI);
  74. }
  75.  
  76. inline double sind(double alpha)
  77. {
  78.     return sin(alpha / (180.0/M_PI));
  79. }
  80.  
  81. inline double cosd(double alpha)
  82. {
  83.     return cos(alpha / (180.0/M_PI));
  84. }
  85.  
  86. template <typename T> 
  87. inline bool isequiv(const T& v1, const T& v2) { return v1 == v2; }
  88.  
  89. template <> 
  90. inline bool isequiv<double>(const double& v1, const double& v2) { return compareDouble(v1, v2); }
  91.  
  92. #endif
  93.